<template>
  <div
    class="share share-back"
    v-if="ishide"
  >
    <div class="text-div">
      <p class="text">复制链接之后，可以使用浏览器或各种的下载工具进行下载</p>
      <i
        class="el-icon-close"
        @click="hide"
      ></i>
    </div>
    <el-input
      v-model="input3"
      class="input-with-select"
    >
      <el-button
        slot="append"
        @click="copy"
      >
        复制
      </el-button>
    </el-input>
  </div>
</template>

<script>
import httpurl from "@/common/API/http-config/config";
export default {
  name: "share",
  data() {
    return {
      ishide: false,
      input3: "",
    };
  },
  methods: {
    hide(val) {
      this.ishide = !this.ishide;
      if (val) {
        this.input3 = `${httpurl.host}downloadUpload?path=${val.path}&title=${val.title}&id=${val.id}`;
      }
    },
    copy() {
      var input = document.createElement("input"); // js创建一个input输入框
      input.value = this.input3; // 将需要复制的文本赋值到创建的input输入框中，this.ruleForm.url这个是我要复制的内容
      document.body.appendChild(input); // 将输入框暂时创建到实例里面
      input.select(); // 选中输入框中的内容
      document.execCommand("Copy"); // 执行复制操作
      document.body.removeChild(input); // 最后删除实例中临时创建的input输入框，完成复制操作
      this.$message({
        message: "复制成功",
        type: "success",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.share {
  position: fixed;
  z-index: 2001;
  width: 40vw;
  height: 14vh;
  border-radius: 10px;
  padding: 10px;
  top: 34vh;
  left: 30vw;

  .text-div {
    width: 95%;
    @include dif-juspb-alic;
    margin: 5px 0 20px 0;
    color: #999;

    .el-icon-close {
      font-size: 22px;
    }

    .el-icon-close:hover {
      color: #06a7ff;
    }
  }

  .text {
    font-size: 14px;
    font-weight: 700;
  }
}

.share ::v-deep .el-input-group__append {
  padding: 0 45px;
}

.share-back {
  background-color: #fff;
  border-bottom: 1px solid #f0f5fc;
  border: 1px solid #e2e2e2;
  box-shadow: 0 0 5px #ccc;
}
</style>